package br.com.jk.empresa;

import br.com.jk.email.Email;
import br.com.jk.entidade.Entidade;
import br.com.jk.telefone.Telefone;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

/**
 * "Teste de alteração"
 *
 * @author camilo
 */
@Entity
@Table(name = EmpresaDao.NAME_TABLE, schema = EmpresaDao.NAME_SCHEMA)
public class Empresa extends Entidade implements Serializable {

  public static final String ATTRIBUTE_EMAIL = "email";
  public static final String ATTRIBUTE_TELEFONE = "telefone";
  @OneToMany(mappedBy = "empresa", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)
  @OnDelete(action = OnDeleteAction.CASCADE)
  @ForeignKey(name = EmpresaDao.NAME_FK_EMPRESA_TELEFONE)
  private List<Telefone> telefone;
  @OneToMany(mappedBy = "empresa", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)
  @OnDelete(action = OnDeleteAction.CASCADE)
  @ForeignKey(name = EmpresaDao.NAME_FK_EMPRESA_EMAIL)
  private List<Email> email;

  public List<Email> getEmail() {
    return email;
  }

  public void setEmail(List<Email> email) {
    this.email = email;
  }

  public List<Telefone> getTelefone() {
    return telefone;
  }

  public void setTelefone(List<Telefone> telefone) {
    this.telefone = telefone;
  }

  @Override
  public int hashCode() {
    int hash = 7;
    hash = 71 * hash + Objects.hashCode(this.telefone);
    hash = 71 * hash + Objects.hashCode(this.email);
    return hash;
  }

  @Override
  public boolean equals(Object obj) {
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }
    final Empresa other = (Empresa) obj;
    if (!Objects.equals(this.telefone, other.telefone)) {
      return false;
    }
    if (!Objects.equals(this.email, other.email)) {
      return false;
    }
    return true;
  }
}
